#include "logger.h"
#include <boost\filesystem.hpp>

namespace utils
{
#define LOG(level, format) \
	va_list args; \
	va_start (args, format); \
	print(level, format, args); \
	va_end (args);

	void logger::log_debug(const char* format, ...)
	{
		LOG("debug", format);
	}

	void logger::log_info(const char* format, ...)
	{
		LOG("info", format);
	}

	void logger::print(const std::string& level, const char* format, va_list args)
	{
		char buffer [256]; //FIXME
		vsnprintf (buffer, 256, format, args);
		printf("[%s] %s: %s\n", level.c_str(), module_name_.c_str(), buffer);
	}

	file& file::instance()
	{
		static file f("server.txt");
		return f;
	}
	
	file::file(const std::string& file_name)
	{
		boost::filesystem::remove(file_name);
		stream = std::ofstream(file_name.c_str());
	}

	void file::write(std::string str)
	{
		stream<<str.c_str()<<std::endl;
	}

	file::~file()
	{
		stream.close();
	}
}